<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\ApiController;
use App\Libraries\Error;
use App\Models\PersonnelDynamics;
use Firebase\JWT\JWT;
use Illuminate\Http\Request;

class PersonnelDynamicsController extends ApiController
{


    public function index(Request $request)
    {
        if (!$request->token) {
            return showError(Error::ERR_ERROR, null, "无效的token!");
        }
        $userInfo = JWT::decode($request->token,env('JWT_KEY'), array('HS256'));
        $exp = $userInfo->exp;
        if (time() > $exp) {
            return showError(Error::ERR_TOKEN_ERROR);
        }
        $userInfo = (array)$userInfo->data;
        $uid = $userInfo['uid'];
        $user = User::where('uid',$uid)->where('status',1)->first();
        if (empty($user)) {
            return showError(Error::ERR_TOKEN_ERROR);
        }
//        $uid = '29221';
        $company_id = $userInfo['company_id'];
        // 搜索内容
        $where = [];
        $content = $request->input('content');
        if (!empty($content))
        {
            $where['content'] = $content;
        }
        $organization_id = $request->input('organization_id');
        if (!empty($organization_id))
        {
            $where['organization_id'] = $organization_id;
        }

        $where['company_id'] = $company_id;
//        $where['status'] = 1;


        $list = PersonnelDynamics::getList($where);

        return showError(Error::ERR_OK,['list'=>$list]);
    }



}
